let blogs = [
    {
        id: 1,
        title: 'nodejs之我看明天',
        author: '鹅是王老五',
        publishedAt: '2025-03-06 15:33:43'
    },
    {
        id: 2,
        title: 'nodejs之我看明天',
        author: '鹅是王老五',
        publishedAt: '2025-03-06 15:33:43'
    },
    {
        id: 3,
        title: 'nodejs之我看明天',
        author: '鹅是王老五',
        publishedAt: '2025-03-06 15:33:43'
    },
    {
        id: 4,
        title: 'nodejs之我看明天',
        author: '鹅是王老五',
        publishedAt: '2025-03-06 15:33:43'
    },
    {
        id: 5,
        title: 'nodejs之我看明天',
        author: '鹅是王老五',
        publishedAt: '2025-03-06 15:33:43'
    },
]
let fn_list = async (ctx) => {


    ctx.render('blogs.html', {
        blogs: blogs
    });
}
let fn_getById = async (ctx) => {
    ctx.body = '898989'
}
let fn_add = async (ctx) => {
    console.log(5566);

    // ctx.render('add.html', {});

    ctx.body = ctx.request.body;
}
let fn_update = async (ctx) => {
    ctx.body = '修改指定id的博客'
}
let fn_del = async (ctx) => {
    ctx.body = '删除指定id的博客'
}

let fn_rederAdd = async (ctx) => {
    ctx.render('add.html');
}
let fn_rederEdit = async (ctx) => {
    let id = (ctx.params.id || 0) * 1;
    console.log(id);

    let blog = blogs.filter(item => item.id === id);
    if (blog.length > 0) {
        ctx.render('edit.html', {
            blog: blog[0]
        });
    } else {
        ctx.body = '要编辑的数据不存在'
    }

}

export default {
    'get /blogs': fn_list,
    'get /blogs/:id': fn_getById,
    'post /blogs': fn_add,
    'put /blogs': fn_update,
    'delete /blogs': fn_del,
    'get /blog/add': fn_rederAdd,
    'get /blog/edit/:id': fn_rederEdit,
}